<template>
	<view class="index">
		<!-- 轮播图区域 -->
		<swiper indicator-dots circular>
			<swiper-item v-for="(item,index) in imgurl" :keys=index>
				<image :src="item"></image>
			</swiper-item>
		</swiper>
		
		<!-- 推荐任务 -->
		<view class=".hot_tasks">
			<view class="tit">推荐任务</view>
			<!-- 任务列表 -->
			<task-List :taskList=taskList></task-List>
			<view class="footer" v-if="isShowfooter">已经到底啦!</view>
		</view>
	</view>
</template>

<script>
	import taskList from '../../components/taskList/taskList'
	
	export default {
		
		components:{"task-List":taskList},
		data() {
			return {
				imgurl:[
					'../../static/schoolImg/1.jpg',
					'../../static/schoolImg/2.jpg',
					'../../static/schoolImg/3.jpg',
					'../../static/schoolImg/4.jpg'
				],
				page: {
					currentPage:0,
					pageSize:5			
				},
				taskList:[],
				isShowfooter:false
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.getTaskList()
		},
		
		//下拉
		onPullDownRefresh() {
			console.log("下拉触发")
			this.page.currentPage=0
			this.taskList=[]
			this.isShowfooter=false
			this.getTaskList()
			setTimeout(function () {
            uni.stopPullDownRefresh();
			},1000)
			
		},
		
		//触底触发
		onReachBottom(){
			console.log("触底触发")
			//判断是否最后一页
			if(this.taskList.length<(this.page.currentPage+1)*this.page.pageSize){
				this.isShowfooter=true //显示到底了
			}else{
				//currentPage+1,请求数据
				console.log("执行到这里")
				this.page.currentPage++
				this.getTaskList()
			}
		},
		
		methods: {
			async getTaskList(){
				var userId=uni.getStorageSync("user").userId;
				if(userId==null){
					userId=0;
				}
				const res=await this.$myRequest({
					url:'/task/queryTaskList/'+this.page.currentPage+'/'+this.page.pageSize+'/'+userId,
					method:'Get',
					data:{
						currentPage:this.page.currentPage,
						pageSize:this.page.pageSize,
						userId
					}	
				})
				this.taskList=[...this.taskList,...res.data.data.records]
			}
		}
	}
</script>

<style lang="scss">
	swiper{
		width: 750rpx;
		height: 355rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	
	.hot_tasks {
		background: #eee;
		overflow: hidden;
		.tit{
			height: 50px;
			line-height: 50px;
			color: #fff;
			text-align: center;
			letter-spacing: 20px;
			background: #50b7ea;
			margin: 7rpx 0;
		}
		.footer{
			width: 750rpx;
			height: 25px;
			line-height: 25px;
			color: while;
			text-align: center;
			font-size: 25rpx;
		}
	}
</style>
